<?php
namespace app\admin\controller;
use think\Db;

class Config extends Main
{
    //首页配置
    public function index(){
        $data = Db::name('index')->select();
        $this->assign('data',$data);
        return $this->fetch();
    }

    //添加首页模块
    public function add(){
        $request = $this->request;
        if($request->isPost()){
            $post     = $this->request->post();
            unset($post['file']);
            $rst = Db::name('index')->insert($post);
            if($rst){
                $this->success('添加成功');
            }else{
                $this->error('添加失败');
            }
        }else{
            return $this->fetch();
        }
    }

    //修改首页模块
    public function edit($id){
        $request = $this->request;
        if($request->isPost()){
            $post     = $this->request->post();
            unset($post['file']);
            $rst = Db::name('index')->where('id',$post['id'])->update($post);
            if($rst){
                $this->success('修改成功');
            }else{
                $this->error('修改失败');
            }
        }else{
            $data = Db::name('index')->where('id',$id)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }
    }

    //删除模块
    public function delete(){
        $id = input('id');
        $rst = Db::name('index')->where('id',$id)->delete();
        if($rst){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }

    //参数配置
    public function config(){
        $request = $this->request;
        if($request->isPost()){
            $post     = $this->request->post();
            $rst = upConfig($post);
            if($rst){
                $this->success('配置成功');
            }else{
                $this->error('配置失败');
            }
        }else{
            $data = config('conf.');
            $this->assign('data',$data);
            return $this->fetch();
        }

    }

}
